package com.yonyou.pmclouds.workflow.config;

import com.yonyou.pmclouds.basecom.dao.BaseMapper;
import com.yonyou.pmclouds.workflow.service.rmiimpl.FlowApproveImp;
import com.yonyou.pmclouds.workflow.service.rmiitf.IFlowApprove;
import com.yonyou.pmclouds.workflow.service.rmiitf.IFlowApproveBuziService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class WorkFlowConfiguration implements BeanPostProcessor {
    private FlowApproveImp flowApproveImp = new FlowApproveImp();

    @Bean
    public IFlowApprove flowApprove() {
        return flowApproveImp;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        if(bean instanceof IFlowApproveBuziService){
            String billType = ((IFlowApproveBuziService)bean).getBillType();
            flowApproveImp.addBuziService(billType,((IFlowApproveBuziService)bean));
            flowApproveImp.addBusinessMapper(billType, (BaseMapper) ((IFlowApproveBuziService) bean).getMapper());
        }

        return bean;
    }


}
